home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#45 (Jun 89)
/
Supe SubCode
/
TrapHook.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-19
|
1KB
|
57 lines
#include "TrapHook.h"
#include <Memory.h>
#include <Menus.h>
#include <strings.h>
#include <OSUtils.h>
#define DrawCharNum 0x083
extern long InsertHookAddr;
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
SetupHook(InfoFunc,HookFunc,TrapNum,HookAddr,NormalTrap)
int (*InfoFunc)();
long HookFunc;
int TrapNum;
TrapHookPointer *HookAddr;
long *NormalTrap;
{
int ParamsSize;
int CodeSize;
long CodeAddr;
THz OldZone;
(*InfoFunc)(&CodeAddr,&CodeSize,&ParamsSize);
/* MAKE SURE TRAP HOOK IS IN SYS HEAP... */
OldZone = GetZone();
SetZone (SystemZone());
*HookAddr = (TrapHookPointer)NewPtr(ParamsSize + CodeSize);
SetZone (OldZone);
*NormalTrap = GetTrapAddress(TrapNum);
(**HookAddr).FuncAddress = HookFunc;
(**HookAddr).TrapAddress = *NormalTrap;
(**HookAddr).HookCallLevel = 0;
BlockMove((Ptr)CodeAddr,(Ptr)&((**HookAddr).Code),CodeSize);
SetTrapAddress((long)&((**HookAddr).Code),TrapNum);
}
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
UnsetTrapHook(HookAddr)
TrapHookPointer HookAddr;
{
int CodeSize;
long CodeAddr;
UnChainHook(&CodeAddr,&CodeSize);
BlockMove((Ptr)CodeAddr,(Ptr)&(HookAddr->Code),CodeSize);
}
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */